import { createTransport } from "nodemailer";
import { reginCode,adminLoginCode } from './mailTemplate/index'
const user = 'keke7426e@163.com'
const name = 'StarRiverCup'
const pass = 'AGPFUXIMXWUYRZQE'
const smtpTransport = createTransport({
  host: 'smtp.163.com',//pop、smtp、imap
  port: 465,
  secure: true,
  auth: {
    user,pass
  }
})

export const sentMail = ({to,title,text,html}) =>{
  return smtpTransport.sendMail({
    from: `${name} <${user}>`,
    to,
    subject:title,
    text,
    html,
  })
}

export const reginCodeMail = ({to,time,code}) => {
  return sentMail({
    to,
    title:'SRC-验证码',
    html:reginCode({code,time,username:to})
  })
}

export const sendAdminCode = ({to,code}) => {
  return sentMail({
    to,
    title:'管理员密码',
    html:adminLoginCode({code,username:to})
  })
}